import { onMounted, ref, computed } from 'vue'
import { Router } from 'vue-router'
import { useStore } from '@/store'


export const productListInit = () => {
  const store = useStore()
  const total = ref(0)
  onMounted(() => {
    store.dispatch('productList/getProductList', { pageNum: 1, pageSize: 5 }).then(res => {
      total.value = res.data.data.total
    })
  })
  const productList = computed(() => store.state.productList.productData)

  return { total, productList }
}

export const editAndDeleteEvents = (router: Router) => {
  const handleEdit = (row: any) => {
    if ( row ) {
      const { goods_id } = row
      router.push({ path: '/goods/edit', query: { id: goods_id }})
    }
  }
  const handleDelete = (row: any) => {
    console.log(row)
  }

  return { handleEdit, handleDelete }
}